package com.example.aigc_education.service.converter;


import com.example.aigc_education.domain.ChatHistory;
import com.example.aigc_education.domain.vo.ChatHistoryVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Mapper(componentModel = "spring")
public interface ChatHistoryConverter {

    /**
     * ChatHistory --> ChatHistoryVO
     */
    @Mapping(target = "chatId", source = "chatId")
    ChatHistoryVO do2vo(ChatHistory chatHistory);

    /**
     *  toChatHistoryVOList
     */
    default List<ChatHistoryVO> toChatHistoryVOList(List<ChatHistory> chatHistories) {
        if (chatHistories == null) {
            return new ArrayList<>();
        }
        return chatHistories.stream()
                .map(this::do2vo)
                .collect(Collectors.toList());
    }
}
